package com.example.dao;

import com.example.pojo.DocumentVideo;
import com.example.pojo.DocumentVideoOfTrainingPlan;
import com.example.pojo.TestPaper;
import com.example.pojo.TestQuestion;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface DocumentVideoOfTrainingPlanCrudRepository extends CrudRepository<DocumentVideoOfTrainingPlan, Integer>, JpaSpecificationExecutor<DocumentVideoOfTrainingPlan> {
    // 查询与特定培训计划关联的试题（已选试题）
    @Query("SELECT tq FROM DocumentVideo tq WHERE tq.id IN (SELECT tp.documentVideoId FROM  DocumentVideoOfTrainingPlan tp WHERE tp.trainingPlanId = :trainingPlanId)")
    List<DocumentVideo> selectedDocumentVideo(Integer trainingPlanId);

    // 查询与特定培训计划未关联的试题（未选试题）
    @Query("SELECT tq FROM DocumentVideo tq WHERE tq.id NOT IN (SELECT tp.documentVideoId FROM DocumentVideoOfTrainingPlan tp WHERE tp.trainingPlanId = :trainingPlanId) AND (tq.agencyId = 0 OR tq.agencyId = :agencyId) AND(tq.status='已发布')")
    List<DocumentVideo> unselectedDocumentVideo(Integer trainingPlanId, Integer agencyId);

    void deleteByDocumentVideoIdAndTrainingPlanId(Integer documentVideoId, Integer trainingPlanId);
}
